using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.Shell;
using EnvDTE80;

namespace Destra.Tools.DACGenerator
{
	public class ErrorList
	{
		private ErrorListProvider m_errorListProvider;
		List<ErrorTask> m_errors;

		public ErrorList(DTE2 dte)
		{
			IServiceProvider serviceProvider = new Microsoft.VisualStudio.Data.ServiceProvider(
				(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);

			m_errorListProvider = new ErrorListProvider(serviceProvider);
			m_errors = new List<ErrorTask>();
		}

		public void Add(Exception e, string filePath)
		{
			ErrorTask errorTask = new ErrorTask(e);
			errorTask.Text = e.ToString();
			errorTask.Document = filePath;

			m_errors.Add(errorTask);
			m_errorListProvider.Tasks.Add(errorTask);
		}

		public void Clear()
		{
			foreach (ErrorTask errorTask in m_errors)
			{
				m_errorListProvider.Tasks.Remove(errorTask);
			}
		}
	}
}
